//
//  connectRobotWifi.m
//  SKaURobot
//
//  Created by cdong on 16/2/24.
//  Copyright © 2016年 cdong. All rights reserved.
//

#import "connectRobotWifi.h"

@implementation connectRobotWifi

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self setUp];
    }
    return self;
}

- (void)loadNagavitionViewWithString:(NSString *)nameString{
    self.navigationV = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 375*matchW, 64)];
    self.navigationV.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"top_bg"]];
    [self addSubview:self.navigationV];
    
    self.navigationVL = [[UILabel alloc]initWithFrame:CGRectMake(((self.frame.size.width - 100)/2), 20, 100, 44)];
    self.navigationVL.text = nameString;
    self.navigationVL.textAlignment = NSTextAlignmentCenter;
    self.navigationVL.textColor = [RGBColorEncapsulation colorWithRGB:0xf8f8f8 alpha:1];
    self.navigationVL.font = [UIFont systemFontOfSize:19];
    [self.navigationV addSubview:self.navigationVL];
    
    self.backBtn = [UIButton buttonWithType:UIButtonTypeSystem];
    self.backBtn.frame = CGRectMake(12*matchW, CGRectGetMinY(self.navigationVL.frame), 40*matchW, CGRectGetHeight(self.navigationVL.frame));
    [self.backBtn setTitle:@"取消" forState:UIControlStateNormal];
    [self.backBtn setTitleColor:[RGBColorEncapsulation colorWithRGB:0xbab9ba alpha:1] forState:UIControlStateNormal];
    self.backBtn.titleLabel.font = [UIFont systemFontOfSize:16];
    [self.navigationV addSubview:self.backBtn];
}

- (void)setUp{
    [self setBackgroundColor:[RGBColorEncapsulation colorWithRGB:0xffffff alpha:1]];
    [self loadNagavitionViewWithString:@"连接"];
    
    UIView *bg_v = [[UIView alloc]initWithFrame:CGRectMake(0, CGRectGetMaxY(self.navigationV.frame), self.frame.size.width,(207- 64)*matchH)];
    bg_v.backgroundColor = [RGBColorEncapsulation colorWithRGB:0xf4f4f4 alpha:1];
    [self addSubview:bg_v];
    
    self.wifiNameImageV = [[UIImageView alloc]initWithFrame:CGRectMake((12+13.5)*matchW, (17+15)*matchH+44+20, 26*matchW, 26*matchH)];
    self.wifiNameImageV.image = [UIImage imageNamed:@"wifi"];
    [self addSubview:self.wifiNameImageV];
    
    self.wifiNameTF = [[UITextField alloc]initWithFrame:CGRectMake(65*matchW, 17*matchH+20+44, self.frame.size.width - 53*matchW - 12*matchW, 60*matchH)];
    self.wifiNameTF.textColor = [RGBColorEncapsulation colorWithRGB:0x333333 alpha:1];
    self.wifiNameTF.placeholder = @"wifi";
//    self.wifiNameTF.userInteractionEnabled = NO;
    if ([self.wifiNameTF respondsToSelector:@selector(setAttributedPlaceholder:)]) {
        UIColor *color = [RGBColorEncapsulation colorWithRGB:0xbab9ba alpha:1];
        UIFont *font = [UIFont systemFontOfSize:15];
        self.wifiNameTF.attributedPlaceholder = [[NSAttributedString alloc]initWithString:@"wifi" attributes:@{NSForegroundColorAttributeName:color,NSFontAttributeName:font}];
    }
    [self addSubview:self.wifiNameTF];
    
    self.wifiNameBtn = [UIButton buttonWithType:UIButtonTypeSystem];
    self.wifiNameBtn.frame = CGRectMake(CGRectGetMaxX(self.wifiNameTF.frame) - 18*matchW - 30*matchW, CGRectGetMinY(self.wifiNameImageV.frame)+4*matchH, 26*matchW, 26*matchH);
    [self.wifiNameBtn setBackgroundImage:[UIImage imageNamed:@"arrow_down"] forState:UIControlStateNormal];
    [self addSubview:self.wifiNameBtn];
    
    self.fillV = [[UIView alloc]initWithFrame:CGRectMake(12*matchW, CGRectGetMaxY(self.wifiNameTF.frame), self.frame.size.width - 24*matchW, 1*matchH)];
    self.fillV.backgroundColor = [RGBColorEncapsulation colorWithRGB:0xe6e6e6 alpha:1];
    [self addSubview:self.fillV];
    
    self.pawImageV = [[UIImageView alloc]initWithFrame:CGRectMake(CGRectGetMinX(self.wifiNameImageV.frame), CGRectGetMaxY(self.fillV.frame) + 15, CGRectGetWidth(self.wifiNameImageV.frame), CGRectGetHeight(self.wifiNameImageV.frame))];
    self.pawImageV.image = [UIImage imageNamed:@"icon_lock"];
    [self addSubview:self.pawImageV];
    
    self.pawTF = [[UITextField alloc]initWithFrame:CGRectMake(CGRectGetMinX(self.wifiNameTF.frame), CGRectGetMaxY(self.fillV.frame), CGRectGetWidth(self.wifiNameTF.frame), CGRectGetHeight(self.wifiNameTF.frame))];
    self.pawTF.textColor = [RGBColorEncapsulation colorWithRGB:0x333333 alpha:1];
    self.pawTF.placeholder = @"请输入wifi密码";
    self.pawTF.secureTextEntry = YES;
    if ([self.pawTF respondsToSelector:@selector(setAttributedPlaceholder:)]) {
        UIColor *color = [RGBColorEncapsulation colorWithRGB:0xbab9ba alpha:1];
        UIFont *font = [UIFont systemFontOfSize:15];
        self.pawTF.attributedPlaceholder = [[NSAttributedString alloc]initWithString:@"请输入wifi密码" attributes:@{NSForegroundColorAttributeName:color,NSFontAttributeName:font}];
    }
    [self addSubview:self.pawTF];
    
    self.pawBtn = [UIButton buttonWithType:UIButtonTypeSystem];
    self.pawBtn.frame = CGRectMake(CGRectGetMaxX(self.wifiNameTF.frame) - 18*matchW - 30*matchW, CGRectGetMinY(self.pawImageV.frame)+4*matchH, 26*matchW, 26*matchH);
    [self.pawBtn setBackgroundImage:[UIImage imageNamed:@"icon_eye"] forState:UIControlStateNormal];
    [self addSubview:self.pawBtn];
    
    self.fillV2 = [[UIView alloc]initWithFrame:CGRectMake(CGRectGetMinX(self.fillV.frame), CGRectGetMaxY(self.pawTF.frame), CGRectGetWidth(self.fillV.frame), CGRectGetHeight(self.fillV.frame))];
    self.fillV2.backgroundColor = [RGBColorEncapsulation colorWithRGB:0xe6e6e6 alpha:1];
    [self addSubview:self.fillV2];
    
    self.fillImageV = [[UIImageView alloc]initWithFrame:CGRectMake(0, CGRectGetMaxY(self.fillV2.frame), self.frame.size.width, 15*matchH)];
    self.fillImageV.image = [UIImage imageNamed:@"pic_waveborder"];
    [self addSubview:self.fillImageV];
    
    self.wifiImageV = [[UIImageView alloc]initWithFrame:CGRectMake((self.frame.size.width - 164*matchW)/2, CGRectGetMaxY(self.fillImageV.frame) + 30*matchH, 164*matchW, 164*matchW)];
    self.wifiImageV.image = [UIImage imageNamed:@"screw_code"];
    [self addSubview:self.wifiImageV];
    
    self.wifiExplainL = [[UILabel alloc]initWithFrame:CGRectMake(0, CGRectGetMaxY(self.wifiImageV.frame) + 27*matchH, self.frame.size.width, 30*matchH)];
    self.wifiExplainL.text = @"生成二维码，连接机器人";
    self.wifiExplainL.textAlignment = NSTextAlignmentCenter;
    self.wifiExplainL.textColor = [RGBColorEncapsulation colorWithRGB:0x999999 alpha:1];
    self.wifiExplainL.font = [UIFont systemFontOfSize:12];
    [self addSubview:self.wifiExplainL];
    
    self.createQRCodeBtn = [UIButton buttonWithType:UIButtonTypeSystem];
    self.createQRCodeBtn.userInteractionEnabled = NO;
    self.createQRCodeBtn.frame = CGRectMake(12*matchW, CGRectGetMaxY(self.wifiExplainL.frame) + 29*matchH, self.frame.size.width - 24*matchH, 45*matchH);
    self.createQRCodeBtn.backgroundColor = [RGBColorEncapsulation colorWithRGB:0xcc222a alpha:1];
    [self.createQRCodeBtn setTitle:@"生成二维码" forState:UIControlStateNormal];
    self.createQRCodeBtn.titleLabel.font = [UIFont systemFontOfSize:18];
    [self.createQRCodeBtn setTitleColor:[RGBColorEncapsulation colorWithRGB:0xffffff alpha:.5] forState:UIControlStateNormal];
    [self.createQRCodeBtn.layer setMasksToBounds:YES];
    [self.createQRCodeBtn.layer setCornerRadius:3];
    [self addSubview:self.createQRCodeBtn];
}

@end
